Page({
  onShow() {
    wx.reportAnalytics('enter_home_programmatically', {})

    // http://tapd.oa.com/miniprogram_experiment/prong/stories/view/1020425689866413543
    if (wx.canIUse('getExptInfoSync')) {
      console.log('getExptInfoSync expt_args_1', wx.getExptInfoSync(['expt_args_1']))
      console.log('getExptInfoSync expt_args_2', wx.getExptInfoSync(['expt_args_2']))
      console.log('getExptInfoSync expt_args_3', wx.getExptInfoSync(['expt_args_3']))
    }
    if (wx.canIUse('reportEvent')) {
      wx.reportEvent('expt_event_1', {expt_data: 1})
      wx.reportEvent('expt_event_2', {expt_data: 5})
      wx.reportEvent('expt_event_3', {expt_data: 9})
      wx.reportEvent('expt_event_4', {expt_data: 200})

      wx.reportEvent('weexpt_event_key_1', {option_1: 1, option_2: 10, option_str_1: 'abc'})
      wx.reportEvent('weexpt_event_key_1', {option_1: 'abc', option_2: '1000', option_str_1: '1'})
    }
  },
  onShareAppMessage() {
    return {
      title: '小程序官方组件展示',
      path: 'page/component/index'
    }
  },
  onShareTimeline() {
    '小程序官方组件展示'
  },

  data: {
    list: [
      {
        id: '1',
        icon: 'view',
        name: '视图容器',
        open: false,
        pages: [
          {
            zh: 'match-media',
            title: '视图容器',
            remark: '',
            url: '/packageComponent/pages/view/match-media/match-media',
            progress: 0,
            docUrl: 'https://developers.weixin.qq.com/miniprogram/dev/component/match-media.html'
          },
          {
            zh: 'view',
            title: '视图容器',
            remark: '',
            url: '/packageComponent/pages/view/view/view',
            progress: 0,
            docUrl: 'https://developers.weixin.qq.com/miniprogram/dev/component/view.html'
          },
          {
            zh: 'scroll-view',
            title: '可滚动视图区域',
            remark: '',
            url: '/packageComponent/pages/view/scroll-view/scroll-view',
            progress: 0,
            docUrl: 'https://developers.weixin.qq.com/miniprogram/dev/component/scroll-view.html'
          },
          {
            zh: 'swiper',
            title: '',
            remark: '',
            url: '/packageComponent/pages/view/swiper/swiper',
            progress: 0,
            docUrl: ''
          },
          {
            zh: 'movable-view',
            title: '',
            remark: '',
            url: '/packageComponent/pages/view/movable-view/movable-view',
            progress: 0,
            docUrl: ''
          },
          {
            zh: 'cover-view',
            title: '',
            remark: '',
            url: '/packageComponent/pages/view/cover-view/cover-view',
            progress: 0,
            docUrl: ''
          }
        ]
      },
      {
        id: '2',
        icon: 'content',
        name: '基础内容',
        open: false,
        pages: [
          {
            zh: 'text',
            title: '视图容器',
            remark: '',
            url: '/packageComponent/pages/content/text/text',
            progress: 0,
            docUrl: ''
          },
          {
            zh: 'icon',
            title: '可滚动视图区域',
            remark: '',
            url: '/packageComponent/pages/content/icon/icon',
            progress: 0,
            docUrl: ''
          },
          {
            zh: 'progress',
            title: '',
            remark: '',
            url: '/packageComponent/pages/content/progress/progress',
            progress: 0,
            docUrl: ''
          },
          {
            zh: 'rich-text',
            title: '',
            remark: '',
            url: '/packageComponent/pages/content/rich-text/rich-text',
            progress: 0,
            docUrl: ''
          },
        ]
      },
      {
        id: '3',
        icon: 'form',
        name: '表单组件',
        open: false,
        pages: [
          {
            zh: 'button',
            title: '视图容器',
            remark: '',
            url: '/packageComponent/pages/form/button/button',
            progress: 0,
            docUrl: ''
          },
          {
            zh: 'checkbox',
            title: '可滚动视图区域',
            remark: '',
            url: '/packageComponent/pages/form/checkbox/checkbox',
            progress: 0,
            docUrl: ''
          },
          {
            zh: 'form',
            title: '',
            remark: '',
            url: '/packageComponent/pages/form/form/form',
            progress: 0,
            docUrl: ''
          },
          {
            zh: 'input',
            title: '',
            remark: '',
            url: '/packageComponent/pages/form/input/input',
            progress: 0,
            docUrl: ''
          },
          {
            zh: 'label',
            title: '',
            remark: '',
            url: '/packageComponent/pages/form/label/label',
            progress: 0,
            docUrl: ''
          },
          {
            zh: 'picker',
            title: '',
            remark: '',
            url: '/packageComponent/pages/form/picker/picker',
            progress: 0,
            docUrl: ''
          },
          {
            zh: 'picker-view',
            title: '',
            remark: '',
            url: '/packageComponent/pages/form/picker-view/picker-view',
            progress: 0,
            docUrl: ''
          },
          {
            zh: 'radio',
            title: '',
            remark: '',
            url: '/packageComponent/pages/form/radio/radio',
            progress: 0,
            docUrl: ''
          },
          {
            zh: 'slider',
            title: '',
            remark: '',
            url: '/packageComponent/pages/form/slider/slider',
            progress: 0,
            docUrl: ''
          },
          {
            zh: 'switch',
            title: '',
            remark: '',
            url: '/packageComponent/pages/form/switch/switch',
            progress: 0,
            docUrl: ''
          },
          {
            zh: 'textarea',
            title: '',
            remark: '',
            url: '/packageComponent/pages/form/textarea/textarea',
            progress: 0,
            docUrl: ''
          },
          {
            zh: 'editor',
            title: '',
            remark: '',
            url: '/packageComponent/pages/form/editor/editor',
            progress: 0,
            docUrl: ''
          },
        ]
      },
      {
        id: '4',
        icon: 'nav',
        name: '导航',
        open: false,
        pages: [
          {
            zh: 'navigator',
            title: '视图容器',
            remark: '',
            url: '/packageComponent/pages/nav/navigator/navigator',
            progress: 0,
            docUrl: ''
          },
        ]
      },
      {
        id: '5',
        icon: 'media',
        name: '媒体组件',
        open: false,
        pages: [
          {
            zh: 'image',
            title: '',
            remark: '',
            url: '/packageComponent/pages/media/image/image',
            progress: 0,
            docUrl: ''
          },
          {
            zh: 'video',
            title: '',
            remark: '',
            url: '/packageComponent/pages/media/video/video',
            progress: 0,
            docUrl: ''
          },
          {
            zh: 'camera',
            title: '',
            remark: '',
            url: '/packageComponent/pages/media/camera/camera',
            progress: 0,
            docUrl: ''
          },
          {
            zh: 'live-pusher',
            title: '',
            remark: '',
            url: '/packageComponent/pages/media/live-pusher/live-pusher',
            progress: 0,
            docUrl: ''
          },
          {
            zh: 'live-player',
            title: '',
            remark: '',
            url: '/packageComponent/pages/media/live-player/live-player',
            progress: 0,
            docUrl: ''
          },
        ]
      },
      {
        id: '6',
        icon: 'map',
        name: '地图',
        open: false,
        pages: [
          {
            zh: 'map',
            title: '',
            remark: '',
            url: '/packageComponent/pages/map/map/map',
            progress: 0,
            docUrl: ''
          },
        ]
      },
      {
        id: '7',
        icon: 'canvas',
        name: '画布',
        open: false,
        pages: [
          {
            zh: 'canvas-2d',
            title: '',
            remark: '',
            url: '/packageComponent/pages/canvas/canvas-2d/canvas-2d',
            progress: 0,
            docUrl: ''
          },
          {
            zh: 'webgl',
            title: '',
            remark: '',
            url: '/packageComponent/pages/canvas/webgl/webgl',
            progress: 0,
            docUrl: ''
          },
        ]
      },
      {
        id: '8',
        icon: 'open',
        name: '开放能力',
        open: false,
        pages: [
          {
            zh: 'ad',
            title: '',
            remark: '',
            url: '/packageComponent/pages/open/ad/ad',
            progress: 0,
            docUrl: ''
          },
          {
            zh: 'open-data',
            title: '',
            remark: '',
            url: '/packageComponent/pages/open/open-data/open-data',
            progress: 0,
            docUrl: ''
          },
          {
            zh: 'web-view',
            title: '',
            remark: '',
            url: '/packageComponent/pages/open/web-view/web-view',
            progress: 0,
            docUrl: ''
          },
        ]
      },
      {
        id: '9',
        icon: 'obstacle-free',
        name: '无障碍访问',
        open: false,
        pages: [
          {
            zh: 'aria-component',
            title: '',
            remark: '',
            url: '/packageComponent/pages/obstacle-free/aria-component/aria-component',
            progress: 0,
            docUrl: ''
          },
        ]
      }
    ],
    theme: 'light'
  },

  onLoad() {
    this.setData({
      theme: wx.getSystemInfoSync().theme || 'light'
    })

    if (wx.onThemeChange) {
      wx.onThemeChange(({theme}) => {
        this.setData({theme})
      })
    }
  },

  kindToggle(e) {
    const id = e.currentTarget.id
    const list = this.data.list
    for (let i = 0, len = list.length; i < len; ++i) {
      if (list[i].id === id) {
        list[i].open = !list[i].open
      } else {
        list[i].open = false
      }
    }
    this.setData({
      list
    })
    wx.reportAnalytics('click_view_programmatically', {})
  }
})
